package model

import (
	"pet-server/basic/config"
	"time"
)

// 订单表
type Order struct {
	Id        uint64    `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	CreatedAt time.Time `gorm:"column:created_at;type:datetime(3);default:NULL;" json:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3);default:NULL;" json:"updated_at"`
	DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
	PetName   string    `gorm:"column:pet_name;type:varchar(20);comment:宠物名称;default:NULL;" json:"pet_name"` // 宠物名称
	AddressId int32     `gorm:"column:address_id;type:int;comment:套餐id;default:NULL;" json:"address_id"`     // 套餐id
	Count     int32     `gorm:"column:count;type:int;comment:库存;default:NULL;" json:"count"`                 // 库存
}

func (o *Order) TableName() string {
	return "order"
}

// 订单创建
func (o *Order) CreateOrder() error {
	return config.DB.Create(o).Error
}

func (o *Order) FirstOrder() error {
	return config.DB.Where("id= ?").First(o).Error
}

// 设置库存
func (o *Order) FirstCount() int64 {
	var count int64
	config.DB.Model(&Order{}).First(count)
	return 10
}
